<?php
/**
 * Created by PhpStorm.
 * User: zzw
 * Date: 17-4-11
 * Time: 下午4:54
 */
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}
class chat extends API_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->_auto();
    }
    public function pushMsg() {
        $rid = $this->data['rid'];
        $content = json_encode(array('content'=>$this->data['msg']));
        $result = send_publishPrivate($this->userinfo['id'],$rid,$content);
        if ($result) {
            // 返回成功
            $this->vdata['returnCode'] = '200';
            $this->vdata['returnInfo'] = '发送成功';
            $this->vdata['secure'] = JSON_SECURE;
            $this->vdata['content'] = $result;
        } else {
            // 返回失败
            $this->vdata['returnCode'] = '100004';
            $this->vdata['returnInfo'] = '发送失败';
            $this->vdata['secure'] = JSON_SECURE;
            $this->vdata['content'] = '';
        }

        $this->_send_json($this->vdata);
    }
    public function info() {
        $ids = explode(',',$this->data['ids']);
        $data = array();
        foreach($ids as $ke=>$id) {
            $info = $this->macc->get_one($id,'uname,photo');
            if(!$info) continue;
            $photo = $info['photo'] ? one_upload($info['photo']) : '';
            $data[$ke]['uname'] = $info['uname'];
            $data[$ke]['photo'] = $photo ? UPLOAD_URL.$photo['url'] : '';
        }

        if ($data) {
            // 返回成功
            $this->vdata['returnCode'] = '200';
            $this->vdata['returnInfo'] = '请求成功';
            $this->vdata['secure'] = JSON_SECURE;
            $this->vdata['content'] = array_values($data);
        } else {
            // 返回失败
            $this->vdata['returnCode'] = '200';
            $this->vdata['returnInfo'] = '请求成功';
            $this->vdata['secure'] = JSON_SECURE;
            $this->vdata['content'] = '';
        }

        $this->_send_json($this->vdata);
    }

    /**
     * 聊天推送
     */
    public function chat_tui(){
        $params = $this->input->post();
        $uid = $params['uid'];
        $type = 5;
        $id = $params['cid'];
        $name = $params['name'];
        $title = $name.'：'.$params['title'];
        if(!$uid || !$type || !$id || !$title){
            // 返回失败
            $this->vdata['returnCode'] = '250';
            $this->vdata['returnInfo'] = '请求失败';
            $this->vdata['secure'] = JSON_SECURE;
            $this->vdata['content'] = '';
        }else{
            //推送
            getui_push($uid,$type,$id,$title,$id);
            $this->vdata['returnCode'] = '200';
            $this->vdata['returnInfo'] = '请求成功';
            $this->vdata['secure'] = JSON_SECURE;
            $this->vdata['content'] = array();
        }
        $this->_send_json($this->vdata);
    }
}